home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 1992 August / info-mac-1992.iso / Source / 3D GrafSys / GrafSys.rel / Demo Sources / xFighter Clip⁄persp < prev   
Text File  |  1992-04-25  |  5KB  |  189 lines

  1. program xFighterDemo2;
  2.  
  3. { 3d GrafSys Demo Program}
  4. { Vers. 1.1 }
  5. { (c) 1992 by Christian Franz }
  6.  
  7. { This program demonstates the use of the grafsys for simple animation using }
  8. { the screenObjects                                                                                        }
  9.  
  10. { note that you can also move the eye by pressing the corresponding keys }
  11.  
  12.     uses
  13. (* Matrix, Transformations, Data3D,*)
  14.         Grafsys, Screen3D;
  15.  
  16.     const
  17.         theWindowID = 400;
  18.         degree = 0.01745329; (* π/180 *)
  19.  
  20.     var
  21.         theWindow: WindowPtr;
  22.         theInt: INTEGER;
  23.         thePort: Graf3DPtr;
  24.         theMaster: Graf3DPtr;
  25.         Pyramid, Cube, xFighter: GrafObjPtr;
  26.         theEvent: EventRecord;
  27.         dx, dy, dz: integer;
  28.         r, PR, VR: Rect;
  29.         SO: ScreenObjPtr;
  30.         dummy: boolean;
  31.  
  32.  
  33.     procedure getmouserot (var dx, dy, dz: integer);
  34.  
  35.         var
  36.             thePoint: point;
  37.  
  38.     begin
  39.         GetMouse(thePoint);
  40.         dx := 0;
  41.         dy := 0;
  42.         dz := 0;
  43.         if (thePoint.h < thePort^.center.h) and (thePoint.v < thePort^.center.v) then (* mouse in quadrant 1 -> xrot*)
  44.             begin
  45.                 dx := 5;
  46.             end;
  47.         if (thePoint.h > thePort^.center.h) and (thePoint.v < thePort^.center.v) then (* mouse in quadrant 2 -> yrot*)
  48.             begin
  49.                 dy := 5;
  50.             end;
  51.         if (thePoint.h > thePort^.center.h) and (thePoint.v > thePort^.center.v) then (* mouse in quadrant 3 -> zrot*)
  52.             begin
  53.                 dz := 5;
  54.             end;
  55.         if (thePoint.h < thePort^.center.h) and (thePoint.v > thePort^.center.v) then (* mouse in quadrant 4 -> idle*)
  56.             begin
  57.             end;
  58.         if button then
  59.             begin
  60.                 dx := -dx;
  61.                 dy := -dy;
  62.                 dz := -dz;
  63.             end;
  64.     end;
  65.  
  66.     const
  67.         closer = 58;  (* option Key *)
  68.         further = 55; (* command key *)
  69.         haltkey = 76; (* keypad enter *)
  70.  
  71.         leftArrow = $7B;
  72.         rightArrow = $7C;
  73.         upArrow = $7E;
  74.         downArrow = $7D;
  75.  
  76.         num1 = $53;
  77.         num2 = $54;
  78.  
  79.     var
  80.  
  81.         theKeys: KeyMap;
  82.         theta, phi: integer;
  83.         pitch: integer;
  84.         update: boolean;
  85.  
  86. begin
  87.     InitCursor;
  88.     theWindow := GetNewWindow(theWindowID, nil, Pointer(-1));
  89.     SetPort(theWindow); (* draw in this window *)
  90.  
  91.     MoveTo(10, 10);
  92.     DrawString('3D GrafSys.      Object:x-Fighter (Clip/persp).    (C) 1992 by CF.');
  93.     InitGrafSys;
  94.     NewGrafport(theWindow^.portRect, thePort);
  95.  
  96.     MoveTo(10, 25 * 15);
  97.     DrawString('Descr. : Press Keypad-Enter to stop');
  98.     MoveTo(10, 26 * 15);
  99.     DrawString('            Option to zoom closer');
  100.     MoveTo(10, 27 * 15);
  101.     DrawString('            Command to move further away');
  102.     MoveTo(10, 28 * 15);
  103.     DrawString('            Move mouse into fighter to rotate it');
  104.  
  105.     PR := theWindow^.PortRect;
  106.     SetRect(VR, thePort^.center.h - 0, thePort^.center.v - 100, thePort^.center.h + 220, thePort^.center.v + 100);
  107.     r := VR;
  108.     for dx := 1 to 3 do
  109.         begin
  110.             InsetRect(r, -2, -2);
  111.             FrameRect(r);
  112.         end;
  113.     SetView(PR, VR);
  114.     SetCenter(thePort^.center.h + 120, thePort^.center.v);
  115.  
  116.     xFighter := GetNewNamedObject('theFighter');
  117.  
  118.     SetEye(true, 0, 0, -200, 0 * degree, 0 * degree, 0 * degree, 1.54079633, true);
  119.     ObjTranslate(xFighter, 0, 0, 0);
  120.     ObjRotate(xFighter, 0 * degree, 0 * degree, 0);
  121.     SetAutoErase(xFighter, true);
  122.     SO := NewScreenObject;
  123.     AttachScreenObject(SO, xFighter); (* Link for all changes *)
  124.     CalcScreenObject(xFighter, TRUE);
  125.     DrawScreenObject(xFighter);
  126.     phi := 0;
  127.     theta := 0;
  128.     pitch := 0;
  129.  
  130.     repeat
  131.         GetMouseRot(dx, dy, dz);
  132.         if (dx + dy + dz <> 0) or (theKeys[closer]) or (theKeys[further]) or update then
  133.             DrawScreenObject(xFighter); (* draw Object *)
  134.         update := false;
  135.         ObjRotate(xFighter, dx * degree, dy * degree, dz * degree);
  136.  
  137.         GetKeys(theKeys);
  138.         if theKeys[further] then
  139.             ObjTranslate(xFighter, 0, 0, 10);
  140.         if theKeys[closer] then
  141.             ObjTranslate(xFighter, 0, 0, -10);
  142.         if theKeys[leftArrow] then
  143.             begin
  144.                 theta := (theta + 5) mod 355;
  145.                 SetEye(true, 0, 0, -200, phi * degree, theta * degree, pitch * degree, 1.54079633, true);
  146.                 update := true;
  147.             end;
  148.  
  149.         if theKeys[rightArrow] then
  150.             begin
  151.                 theta := (theta - 5) mod 355;
  152.                 SetEye(true, 0, 0, -200, phi * degree, theta * degree, pitch * degree, 1.54079633, true);
  153.                 update := true;
  154.             end;
  155.  
  156.         if theKeys[upArrow] then
  157.             begin
  158.                 phi := (phi + 5) mod 355;
  159.                 SetEye(true, 0, 0, -200, phi * degree, theta * degree, pitch * degree, 1.54079633, true);
  160.                 update := true;
  161.             end;
  162.  
  163.         if theKeys[downArrow] then
  164.             begin
  165.                 phi := (phi - 5) mod 355;
  166.                 SetEye(true, 0, 0, -200, phi * degree, theta * degree, pitch * degree, 1.54079633, true);
  167.                 update := true;
  168.             end;
  169.  
  170.         if theKeys[num1] then
  171.             begin
  172.                 pitch := (pitch + 5) mod 355;
  173.                 SetEye(true, 0, 0, -200, phi * degree, theta * degree, pitch * degree, 1.54079633, true);
  174.                 update := true;
  175.             end;
  176.  
  177.         if theKeys[num2] then
  178.             begin
  179.                 pitch := (pitch - 5) mod 355;
  180.                 SetEye(true, 0, 0, -200, phi * degree, theta * degree, pitch * degree, 1.54079633, true);
  181.                 update := true;
  182.             end;
  183.  
  184.         CCalcScreenObject(xFighter, TRUE);
  185.     until theKeys[haltkey];
  186.     repeat
  187.         dummy := GetNextEvent(everyEvent, theEvent);
  188.     until theevent.what = mousedown;
  189. end.